<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:th="http://www.thymeleaf.org"
	xmlns:crm="http://www.thymeleaf.org/crm"
	xmlns:dt="http://github.com/dandelion/datatables">

<head th:replace="fragment/common :: header"></head>
<body>

	<div th:replace="fragment/common :: topnav"></div>

	<div id="wrap">

		<div class="container-fluid">

			<div class="row">
				<div class="span8">
					<h4 th:if="${newLead}">New Potential</h4>
					<h4 th:if="${view}">View Potential Details</h4>
					<h4 th:if="${edit}">Edit Potential</h4>
				</div>
				<div class="span4 pull-right">
					<div class="btn-group pull-right">
						<a class="btn btn-primary" href="list"> <i
							class="fa fa-plus-square"></i> View Potentials
						</a>
						<!-- 
						<button class="btn btn-warning">
							<i class="fa fa-upload"></i> Import Potentials
						</button>
						 -->
					</div>
				</div>
			</div>


			<form
				th:action="${id == null} ? @{/potential/save} : @{/potential/update}"
				class="form-horizontal small labels" method="POST"
				th:object="${potential}">
				<input type="hidden" th:field="*{id}" />

				<div class="row-fluid" th:if="${edit}">
					<div class="alert alert-success" th:if="${message != null}">
						<button type="button" class="close" data-dismiss="alert">&times;</button>
						<b>Success!</b> Potential updated successfully.
					</div>
				</div>

				<div class="row-fluid" th:if="${newLead or view}">
					<div class="alert alert-success" th:if="${message != null}">
						<button type="button" class="close" data-dismiss="alert">&times;</button>
						<b>Success!</b> Potential saved successfully.
					</div>
				</div>



				<fieldset>
					<legend>
						Potential Information

						<div class="pull-right">
							<button type="submit" class="btn btn-primary" th:if="${!view}">Save</button>
							<button type="button" class="btn" th:if="${!view}">Cancel</button>



							<a class="btn btn-primary" th:href="@{/potential/edit(id=*{id})}"
								th:if="${view}">Edit</a> <a class="btn btn-danger"
								th:href="@{/potential/delete(id=*{id})}" th:if="${view}">Delete</a>
							<a class="btn btn-info" th:href="@{/potential/copy(id=*{id})}"
								th:if="${view}">Copy</a> <a class="btn" href="list"
								th:if="${view}">Back</a>

						</div>

					</legend>


					<div class="row-fluid ">


						<div class="span4">

							<div class="control-group">
								<label class="control-label" for="name">Potential Name</label>
								<div class="controls">
									<input type="text" class="span12" th:field="*{name}"
										th:disabled="${view}" />

								</div>
							</div>
						</div>

						<div class="span4">

							<div class="control-group">
								<label class="control-label" for="amount">Amount</label>
								<div class="controls">
									<input type="text" class="span12" th:field="*{amount}"
										required="required" th:disabled="${view}" />

								</div>
							</div>
						</div>
						
						
						<div class="span4">

							<div class="control-group">
								<label class="control-label" for="type">Type</label>
								<div class="controls">
									<select th:field="*{type}" class="span12" th:disabled="${view}">
										<option th:each="s : ${potentialTypes}" th:value="${s.id}"
											th:text="#{${s.key}}" th:selected="${potential.type eq s}"></option>
									</select>


								</div>
							</div>
						</div>

					</div>

					<div class="row-fluid ">

						

						<div class="span4">
							<div class="control-group">
								<label class="control-label" for="source">Lead Source</label>
								<div class="controls">

									<select th:field="*{leadSource}" class="span12"
										th:disabled="${view}">
										<option th:each="s : ${sourceList}" th:value="${s.id}"
											th:text="#{${s.key}}"
											th:selected="${potential.leadSource eq s}"></option>
									</select>

								</div>
							</div>
						</div>
						
						
						<div class="span4">

							<div class="control-group">
								<label class="control-label" for="source">Sales Stage</label>
								<div class="controls">

									<select th:field="*{salesStage}" class="span12"
										th:disabled="${view}">
										<option th:each="s : ${salesStageList}" th:value="${s.id}"
											th:text="#{${s.key}}"
											th:selected="${potential.salesStage eq s}"></option>
									</select>

								</div>
							</div>
						</div>
						
						<div class="span4">

							<div class="control-group">
								<label class="control-label" for="probability">Probability</label>
								<div class="controls well">

									<input type="hidden" th:field="*{probability}"></input>
										
									<div id="slide" data-slider-max="100"  data-slider-orientation="horizontal" data-slider-tooltip="hide"></div>	
									<span class="label label-info" th:text="*{probability}" id="slidespan"></span>

								</div>
							</div>
						</div>
						

					</div>


					

					<div class="row-fluid ">

						<div class="span6">

							<div class="control-group">
								<label class="control-label" for="fax">Related To</label>
								<div class="controls">
									<input type="radio" value="User" checked="checked"
										name="assign" th:disabled="${view}">Account</input> <input
										type="radio" value="Team" name="assign" th:disabled="${view}">Contact</input>

									<select th:field="*{assignedUser}" th:disabled="${view}">
										<option th:each="u : ${users}" th:value="${u}" th:text="${u}"></option>
									</select> <select th:field="*{assignedTeam}" th:disabled="${view}">
										<option th:each="t : ${teams}" th:value="${t}" th:text="${t}"></option>
									</select>


								</div>
							</div>
						</div>


						<div class="span6">

							<div class="control-group">
								<label class="control-label" for="fax">Assigned To</label>
								<div class="controls">
									<input type="radio" value="User" checked="checked"
										name="assign" th:disabled="${view}">User</input> <input
										type="radio" value="Team" name="assign" th:disabled="${view}">Team</input>

									<select th:field="*{assignedUser}" th:disabled="${view}">
										<option th:each="u : ${users}" th:value="${u}" th:text="${u}"></option>
									</select> <select th:field="*{assignedTeam}" th:disabled="${view}">
										<option th:each="t : ${teams}" th:value="${t}" th:text="${t}"></option>
									</select>


								</div>
							</div>
						</div>

					</div>
					
					<div class="row-fluid ">

						<div class="span12">

							<div class="control-group">
								<label class="control-label" for="description">Description</label>
								<div class="controls">

									<textarea rows="6" cols="20" th:field="*{description}"
										class="span12" th:disabled="${view}"> </textarea>
								</div>
							</div>
						</div>

						

					</div>
					


				</fieldset>


				<div class="row-fluid">

					<div class="pull-right">
						<button type="submit" class="btn btn-primary" th:if="${!view}">Save</button>
						<button type="button" class="btn" th:if="${!view}">Cancel</button>



						<a class="btn btn-primary" th:href="@{/lead/edit(id=*{id})}"
							th:if="${view}">Edit</a> <a class="btn" href="list"
							th:if="${view}">Back</a>
					</div>

				</div>


			</form>


		</div>


		<div id="push"></div>
	</div>

	<!-- 
	<footer th:replace="fragment/common :: footer"></footer>
	 -->

	<script type="text/javascript">
		$(document).ready(
				function() {

					$('input[required="true"]').closest(".control-group")
							.children("label").prepend(
									'<i class="icon-asterisk"></i>');

					$('input[required="required"]').closest(".control-group")
							.children("label").prepend(
									'<i class="icon-asterisk"></i>');

					$("#assignedTeam").hide();

					$("input[value='User']").click(function() {
						if ($(this).is(":checked")) {

							alert('user clicked');

							$("#assignedUser").show();
							$("#assignedTeam").hide();
						}

					});

					$("input[value='Team']").click(function() {
						alert('team clicked');
						if ($(this).is(":checked")) {
							$("#assignedTeam").show();
							$("#assignedUser").hide();
						}
					});
					
					
					
					
					$('#slide').slider({
				          formater: function(value) {
				           
				            $("#probability").val(value);
				            $('#slidespan').text(value);
				          }
				        });

				});
	</script>



</body>
</html>